package server.configuration;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class ServerConfiguration implements Serializable
{
	private static final long serialVersionUID = 1L;
	private static final ArrayList<ServerConfiguration> configs;
	private int port;
	private boolean portSet = false;
	private String databaseLocation;
	private String databaseUsername;
	private String databasePassword;
	private List<String> knownServers;
	private long lastSynchronized;
	
	static
	{
		configs = new ArrayList<ServerConfiguration>();
		configs.add(new ServerConfiguration(62455, "jdbc:mysql://localhost:3306/Capstone", "root", "password"));
		configs.add(new ServerConfiguration(62456, "jdbc:mysql://localhost:3306/Capstone2", "root", "password"));
	}
	public ServerConfiguration()
	{
		
	}
	public ServerConfiguration(int port, String databaseLocation, String databaseUsername, String databasePassword)
	{
		this.knownServers = new ArrayList<String>();
		this.port = port;
		this.databaseLocation = databaseLocation;
		this.databaseUsername = databaseUsername;
		this.databasePassword = databasePassword;
	}
	public static ServerConfiguration getConfig(int i)
	{
		return configs.get(i);
	}
	public int getPort()
	{
		return port;
	}
	@XmlElement
	public void setPort(int port)
	{
		if (!this.portSet)
		{
			this.port = port;
			this.portSet = true;
		}
	}
	public String getDatabaseLocation()
	{
		return databaseLocation;
	}
	@XmlElement
	public void setDatabaseLocation(String databaseLocation)
	{
		if (this.databaseLocation == null)
			this.databaseLocation = databaseLocation;
	}
	public String getDatabaseUsername()
	{
		return databaseUsername;
	}
	@XmlElement
	public void setDatabaseUsername(String databaseUsername)
	{
		if (this.databaseUsername == null)
			this.databaseUsername = databaseUsername;
	}
	public String getDatabasePassword()
	{
		return databasePassword;
	}
	@XmlElement
	public void setDatabasePassword(String databasePassword)
	{
		if (this.databasePassword == null)
			this.databasePassword = databasePassword;
	}
	public List<String> getKnownServers()
	{
		return knownServers;
	}
	@XmlElement(name = "knownServer")
	public void setKnownServers(List<String> knownServers)
	{
		if (this.knownServers == null)
			this.knownServers = knownServers;
	}
	public void addKnownServer(String serverLocation)
	{
		if (knownServers == null)
			knownServers = new ArrayList<String>();
		
		knownServers.add(serverLocation);
	}
	public long getLastSynchronized()
	{
		return lastSynchronized;
	}
	@XmlElement
	public void setLastSynchronized(long lastSynchronized)
	{
		this.lastSynchronized = lastSynchronized;
	}
}
